package day14_junit_reflect_annotation_proxy.com.itheima.d2_reflect;

import org.junit.Test;

import java.lang.reflect.Method;

public class Test4_Method {
    @Test
    public void testGetMethod() throws Exception{
        Class<Cat> c = Cat.class;
        Method[] methods = c.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println(method.getName() + "-->" + method.getParameterCount());
        }
        Method eat1 = c.getDeclaredMethod("eat");
        Method eat2 = c.getDeclaredMethod("eat", String.class);

        Cat cat = new Cat();
        Object result = eat1.invoke(cat);
        System.out.println(result);

        eat2.setAccessible(true);
        Object result2 = eat2.invoke(cat, "鱼");
        System.out.println(result2);

    }
}
